return babl;
}
+
+static int
+is_component_duplicate (Babl *babl, int luma, int chroma, int alpha)
+{
+ if (babl->component.luma != luma ||
+ babl->component.chroma != chroma ||
+ babl->component.alpha != alpha)
+ return 0;
+
+ return 1;
+}
+
+
Babl *
babl_component_new (void *first_arg,
...)
int luma = 0;
int chroma = 0;
int alpha = 0;
- const char *arg = (char *) first_arg;
+ const char *name = first_arg;
+ const char *arg;
va_start (varg, first_arg);
else
{
- babl_fatal ("unhandled argument '%s' for format '%s'", arg, first_arg);
+ babl_fatal ("unhandled argument '%s' for component '%s'", arg, name);
}
}
va_end (varg);
- babl = babl_db_exist (db, id, first_arg);
+ babl = babl_db_exist (db, id, name);
+ if (id && !babl && babl_db_exist (db, 0, name))
+ babl_fatal ("Trying to reregister BablComponent '%s' with different id!",
+ name);
+
if (babl)
{
/* There is an instance already registered by the required id/name,
- * returning the preexistent one instead.
+ * returning the preexistent one instead if it doesn't differ.
*/
+ if (!is_component_duplicate (babl, luma, chroma, alpha))
+ babl_fatal ("BablComponent '%s' already registered "
+ "with different attributes!", name);
return babl;
}
- babl = component_new (first_arg, id, luma, chroma, alpha);
+ babl = component_new (name, id, luma, chroma, alpha);
/* Since there is not an already registered instance by the required
* id/name, inserting newly created class into database.
{
Babl *babl;
- /* i is desintation position */
+ /* i is destination position */
int i, j, component_found = 0;
for (i = 0; i < model->components; i++)
{
return babl;
}
+static int
+is_format_duplicate (Babl *babl,
+ int planar,
+ int components,
+ BablModel *model,
+ BablComponent **component,
+ BablSampling **sampling,
+ BablType **type)
+{
+ int i;
+
+ if (babl->format.planar != planar ||
+ babl->format.components != components ||
+ babl->format.model != model)
+ return 0;
+
+ for (i = 0; i < components; i++)
+ {
+ if (babl->format.component[i] != component[i] ||
+ babl->format.sampling[i] != sampling[i] ||
+ babl->format.type[i] != type[i])
+ return 0;
+ }
+ return 1;
+}
+
Babl *
babl_format_new (void *first_arg,
...)
name = create_name (model, components, component, type);
babl = babl_db_exist (db, id, name);
+ if (id && !babl && babl_db_exist (db, 0, name))
+ babl_fatal ("Trying to reregister BablFormat '%s' with different id!", name);
+
if (babl)
{
/* There is an instance already registered by the required id/name,
- * returning the preexistent one instead.
+ * returning the preexistent one instead if it doesn't differ.
*/
+ if (!is_format_duplicate (babl, planar, components, model,
+ component, sampling, type))
+ babl_fatal ("BablFormat '%s' already registered "
+ "with different content!", name);
+
babl_free (name);
return babl;
}
return babl;
}
+static int
+is_model_duplicate (Babl *babl, int components, BablComponent **component)
+{
+ int i;
+
+ if (babl->model.components != components)
+ return 0;
+
+ for (i = 0; i < components; i++)
+ {
+ if (babl->model.component[i] != component[i])
+ return 0;
+ }
+
+ return 1;
+}
+
+
Babl *
babl_model_new (void *first_argument,
...)
name = babl_model_create_name (components, component);
babl = babl_db_exist (db, id, name);
+ if (id && !babl && babl_db_exist (db, 0, name))
+ babl_fatal ("Trying to reregister BablModel '%s' with different id!", name);
if (! babl)
{
}
else
{
- babl_log ("Warning: BablModel '%s' already registered!", name);
+ if (!is_model_duplicate (babl, components, component))
+ babl_fatal ("BablModel '%s' already registered "
+ "with different components!", name);
}
babl_free (name);
return babl;
}
+static int
+is_type_duplicate (Babl *babl, int bits)
+{
+ if (babl->type.bits != bits)
+ return 0;
+
+ return 1;
+}
+
Babl *
babl_type_new (void *first_arg,
...)
long max = 255;
double min_val = 0.0;
double max_val = 0.0;
-
- const char *arg = first_arg;
+ const char *name = first_arg;
+ const char *arg;
va_start (varg, first_arg);
else
{
- babl_fatal ("unhandled argument '%s' for format '%s'", arg, first_arg);
+ babl_fatal ("unhandled argument '%s' for format '%s'", arg, name);
}
}
va_end (varg);
- babl = babl_db_exist (db, id, first_arg);
+ babl = babl_db_exist (db, id, name);
+ if (id && !babl && babl_db_exist (db, 0, name))
+ babl_fatal ("Trying to reregister BablType '%s' with different id!", name);
+
if (babl)
{
/* There is an instance already registered by the required id/name,
- * returning the preexistent one instead.
+ * returning the preexistent one instead if it doesn't differ.
*/
+
+ if (!is_type_duplicate (babl, bits))
+ babl_fatal ("BablType '%s' already registered "
+ "as different type!", name);
+
return babl;
}
- babl = type_new (first_arg, id, bits);
+ babl = type_new (name, id, bits);
/* Since there is not an already registered instance by the required
* id/name, inserting newly created class into database.
babl_type_from_id (BABL_U8),
babl_component_from_id (BABL_LUMA),
NULL);
+
+ /* overriding name, since the generated name would be wrong due
+ * to differing types
+ */
babl_format_new (
"name", "Y'CbCr u8",
+ "planar",
babl_model_from_id (BABL_YCBCR),
babl_type_from_id (BABL_U8_LUMA),
+ babl_sampling (1, 1),
babl_component_from_id (BABL_LUMA),
babl_type_from_id (BABL_U8_CHROMA),
+ babl_sampling (2, 2),
babl_component_from_id (BABL_CB),
+ babl_sampling (2, 2),
babl_component_from_id (BABL_CR),
NULL);
babl_format_new (
babl_component_from_id (BABL_LUMINANCE),
NULL);
- /* overriding name, since the generated name would be wrong due
- * to differing types
- */
- babl_format_new (
- "name", "Y'CbCr u8",
- babl_model_from_id (BABL_YCBCR),
- babl_type_from_id (BABL_U8_LUMA),
- babl_component_from_id (BABL_LUMA),
- babl_type_from_id (BABL_U8_CHROMA),
- babl_component_from_id (BABL_CB),
- babl_component_from_id (BABL_CR),
- NULL);
babl_format_new (
babl_model_from_id (BABL_YCBCR),
babl_type_from_id (BABL_FLOAT),
{
babl_format_new (
"name", "Y'CbCr u8",
- "id", BABL_YCBCR420,
"planar",
babl_model_from_id (BABL_YCBCR),
babl_type_from_id (BABL_U8_LUMA),
NULL);
Babl *yuv8 = babl_format_new (
"name", "Y'CbCr u8",
+ "planar",
babl_model ("Y'CbCr"),
babl_type ("u8-luma"),
+ babl_sampling (1, 1),
babl_component ("Y'"),
babl_type ("u8-chroma"),
+ babl_sampling (2, 2),
babl_component ("Cb"),
babl_component ("Cr"),
NULL);
NULL);
Babl *yuv8 = babl_format_new (
"name", "Y'CbCr u8",
+ "planar",
babl_model ("Y'CbCr"),
babl_type ("u8-luma"),
+ babl_sampling (1, 1),
babl_component ("Y'"),
babl_type ("u8-chroma"),
+ babl_sampling (2, 2),
babl_component ("Cb"),
babl_component ("Cr"),
NULL);